﻿using System.Runtime.Serialization;
using GMME.Util;
using UnityEngine;
using UnityEngine.Scripting;

namespace GMME.Model.Rtm.Req
{
    [DataContract]
    public class PublishRtmPeerMessageReq : RtmMessageContent
    {
        [DataMember(Name = "peerId")]
        [Preserve]
        public string PeerId { get; set; }


#if UNITY_ANDROID
        internal static PublishRtmPeerMessageReq ConvertPublishRtmPeerMessageReq(AndroidJavaObject javaObject)
        {
            if (javaObject != null)
            {
                var result = new PublishRtmPeerMessageReq();
                result.PeerId = javaObject.Call<string>("getPeerId");
                var content = ConvertRtmMessageContent(javaObject);
                result.MessageBytes = content.MessageBytes;
                result.MessageString = content.MessageString;
                result.MessageType = content.MessageType;
                return result;
            }

            return null;
        }

        public static AndroidJavaObject ConvertPublishRtmPeerMessageReq(PublishRtmPeerMessageReq req)
        {
            var androidJavaObject =
                new AndroidJavaObject("com.huawei.game.gmme.model.rtm.PublishRtmPeerMessageReq");
            androidJavaObject.Set("messageType", req.MessageType);
            androidJavaObject.Set("messageString", req.MessageString);
            if (req.MessageType == 2)
            {
                req.MessageString = "";
                TransferUtil.CsharpArrayToJavaArray(androidJavaObject, req.MessageBytes, "setMessageBytes");
            }

            androidJavaObject.Set("peerId", req.PeerId);
            return androidJavaObject;
        }
#endif
    }
}